package vip.kqsy.cloud.ai.server.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.kqsy.cloud.ai.server.pojo.dto.SessionAddDTO;
import vip.kqsy.cloud.ai.server.pojo.vo.UserSessionDTO;
import vip.kqsy.cloud.ai.server.service.AiSessionService;
import vip.kqsy.cloud.core.security.user.KqsyUserContext;
import vip.kqsy.cloud.core.web.res.R;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 聊天上下文 前端控制器
 * </p>
 *
 * @author cenjunjie
 * @since 2023-07-08
 */
@RestController
@RequestMapping("/aiSession")
@Api(tags = "AI上下文")
@RequiredArgsConstructor
@Valid
public class AiSessionController {
    private final AiSessionService aiSessionService;

    @ApiOperation("创建会话")
    @PostMapping("add")
    public R<Long> add(@Valid SessionAddDTO dto) {
        dto.setUserId(KqsyUserContext.getUser().getId());
        Long aLong = aiSessionService.add(dto);
        return R.ok(aLong);
    }

    @ApiOperation("查询用户会话")
    @GetMapping("listByUserId")
    public R<List<UserSessionDTO>> listByUserId() {
        List<UserSessionDTO> list = aiSessionService.listByUerId(KqsyUserContext.getUser().getId());
        return R.ok(list);
    }

    @ApiOperation("删除会话")
    @PostMapping("delete")
    public R<Void> delete(@NotNull @ApiParam("SessionId") Long id) {
        aiSessionService.delete(id);
        return R.ok();
    }

}
